package com.yunhe.fineart;

import android.content.Intent;

import androidx.annotation.NonNull;

import com.yunhe.fineart.utils.Utils;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;


public class MainActivity extends FlutterActivity {
    private static final String CHANNEL = "com.yunhe.fineart/platform";
    public static MethodChannel methodChannel = null;

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);
        methodChannel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL);
        methodChannel.setMethodCallHandler(
                (call, result) -> {
                    // Note: this method is invoked on the main thread.
                    if (call.method.equals("uuid")) {
                        String uuid = Utils.uuid(this);

                        if (uuid.length() > 0) {
                            result.success(uuid);
                        } else {
                            result.error("UNAVAILABLE", "uuid not available.", null);
                        }
                    } else if (call.method.equals("start_course")) {
                        String url = call.argument("url");
                        Intent intent = new Intent(MainActivity.this, CourseActivity.class);
                        intent.putExtra("url", url);

                        startActivity(intent);
                    } else if (call.method.equals("hdimage")) {
                        String url = call.argument("url");
                        Intent intent = new Intent(MainActivity.this, HDImageActivity.class);
                        intent.putExtra("url", url);

                        startActivity(intent);
                    } else {
                        result.notImplemented();
                    }
                }
        );

    }

}
